def isPrime(a):    
    if a == 1: return False    
    test = True    
    x = a - 1    
    while x > 1:    
        if not a % x:    
            test = False                
            break    
        x -= 1        
    return test   
      
n = input()  
m = []  
for i in range(len(n)):  
    for x in range(i + 1,len(n) + 1):  
        a = int(n[i:x]) 
        if isPrime(a):  
            m += [a]  
print(max(m) if m else 0)
